<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Carousel extends Model
{
    const TYPE_PRODUCT = 1;
    const TYPE_CATEGORY = 2;
    const CAROUSEL_TYPE = [
        self::TYPE_CATEGORY => "商品分类",
        self::TYPE_PRODUCT  => "商品详情",
    ];
    const CAROUSEL_STATUS = [
        'on'  => ['value' => 1, 'text' => '是', 'color' => 'success'],
        'off' => ['value' => 0, 'text' => '否', 'color' => 'danger'],
    ];

    public function cover()
    {
        return $this->hasOne(Image::class, 'type_id')
            ->where('type', Image::CAROUSEL);
    }
}
